package com.yishe.biz.tech.userinfo;

import com.yishe.biz.BaseBiz;
import com.yishe.context.BaseContextHandler;
import com.yishe.entites.mysql.YsStaff;
import com.yishe.mapper.mysql.YsStaffMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author : chusifeng
 * @version :
 * @date :Create in 2021/4/21 17:09
 * @description: 员工信息管理
 * @package com.yishe.biz.tech.userinfo
 * @className StaffBiz
 */
@Service
@Slf4j
public class StaffBiz extends BaseBiz<YsStaffMapper, YsStaff> {
    /**
     * 根据工号删除员工
     * @param account
     */
    public void deleteStaff(String account) {
        YsStaff ysStaff = new YsStaff();
        ysStaff.setAccount(account);
        this.delete(ysStaff);
    }

    /**
     * 保存员工信息
     * @param ysStaff
     */
    public void saveStaff(YsStaff ysStaff) {
        if (null == ysStaff.getId()) {
            ysStaff.setStatus(1);
            ysStaff.setCreateId(BaseContextHandler.getUserCode());
            ysStaff.setCreateTime(new Date());
            //insert
            this.insert(ysStaff);
        } else {
            this.updateById(ysStaff);
        }
    }

    /**
     * 根据工号查询员工信息
     * @param account
     */
    public YsStaff getStaffInfo(String account) {
        YsStaff ysStaff = new YsStaff();
        ysStaff.setAccount(account);
        return this.selectOne(ysStaff);
    }
}
